import websitebase


class houbi(websitebase.websitebase):

    _url_ticker = "http://api.huobi.com/staticmarket/detail_%s_json.js"

    def __init__(self):
        websitebase.websitebase.__init__(self)

    def getlast(self, symbol = "btc"):
        if self._string_is_empty(symbol):
            print("houbi.getlast:输入的参数不能为空")
            return
        jdata = self.ticker(symbol)
        return jdata['p_new']

    # symbol:"btc"/"ltc"
    def ticker(self, symbol = "btc"):
        if self._string_is_empty(symbol):
            print("houbi.ticker:输入的参数不能为空")
            return
        if symbol != "btc" and symbol != "ltc":
            print("houbi.ticker:输入的参数不正确")
            return
        url = self._url_ticker % (str(symbol))
        return self._req_json(url)

if __name__ == "__main__":
    # t = time.time()
    a = houbi()
    print(a.getlast("btc"))
    # print(time.time()-t)



# url = "https://www.houbi.cn/api/v1/ticker.do?symbol=btc_cny"
#
# re = urllib.request.urlopen(url)
# data = re.read().decode("utf-8")
# print(data)
# jdata = json.loads(data)
# print(jdata)
# print(jdata['ticker']['last'])
